<?php
$filename = mysql_escape_string($_POST ["filename"]);
$filelabel = mysql_escape_string($_POST ["filelabel"]);
$tag = mysql_escape_string($_POST ["tag"]);

require_once ("../../config.inc.php");
require_once ("../../include/mysql.inc.php");
require_once ("../../include/res.inc.php");
require_once ("../../include/resTag.inc.php");
$ResDao =new Res();
$ResTagDao	=new ResTag();

$name = $_FILES ["file"] ["name"];
$Type = $_FILES ["file"] ["type"];
$Size = ($_FILES ["file"] ["size"] ) ;
$path ="../../res/upload/";
function get_total_millisecond()
{
	$time = explode (" ", microtime () );
	$time = $time [1] . ($time [0] * 1000);
	$time2 = explode ( ".", $time );
	$time = $time2 [0];
	return $time;
}
$fileExtensionName=strtolower(eregi_replace(".+(\..+)","\\1",$name));
$newName=get_total_millisecond().$fileExtensionName;
if($Type == "application/pdf")
		{
			$Type='1';
		}
elseif ((($_FILES["file"]["type"] == "image/gif")
		|| ($_FILES["file"]["type"] == "image/jpeg")
		||	($_FILES["file"]["type"] == "image/jpg")
		|| ($_FILES["file"]["type"] == "image/pjpeg")|| ($_FILES["file"]["type"] == "image/png")))
		{
			$Type ='2';
		}
		elseif($_FILES["file"]["type"] == "text/plain")
		{
			$Type='3';
		}
		elseif ((($_FILES["file"]["type"] == "application/msword")
		|| ($_FILES["file"]["type"] == "application/vnd.ms-excel")
		||	($_FILES["file"]["type"] == "application/vnd.ms-powerpoint")
		))
				{
					$Type='4';
				}
				elseif ((($_FILES["file"]["type"] == "application/x-zip-compressed")
						|| ($_FILES["file"]["type"] == "application/octet-stream")
						
				))
				{
					$Type='5';
				}
				else
				{
					$Type='6';
				}		 
move_uploaded_file ( $_FILES ["file"] ["tmp_name"], "../../res/upload/" . $newName);

$flag = $ResDao->add($filename, $path, $Type, $Size, $tag);
if ($flag) {
	echo "上传资源成功！<br/><a href='../../admin/resList.php'>跳转到资源列表</a>";
}
else {
	echo "上传资源失败！<br/><a href='' onclick='javascript:history.back(-1);'>返回到资源上传页面</a>";
}?>